// pages/underground/underground.js
var QQMapWX = require("../../qqmap-wx-jssdk.js");

// 实例化API核心类
var qqmapsdk = new QQMapWX({
  key: 'G52BZ-YVVL6-4JVST-EYZML-KOPJH-XDBMV' // 必填
});
Page({

  /**
   * 页面的初始数据
   */
  data: {
    firstStation: '你要从哪里出发?',
    finallyStation: '你要去哪里?',

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    if (options.firstStation) {
      this.setData({
        firstStation: options.firstStation,
        finallyStation: options.finallyStation,
        firstlat: options.firstlat,
        firstlng: options.firstlng,
        finallylat: options.finallylat,
        finallylng: options.finallylng,
      })
    }
  },
  toSelected: function() {
    console.log(this.data.finallyStation)
    wx.navigateTo({
      url: 'first/first'
    })
  },
  toSelected2: function() {
    console.log(this.data.firstStation)
    wx.navigateTo({
      url: "finally/finally"
    })
  },

  formSubmit(e) {
    var _this = this;
    console.log(this.data.firstlat)
    console.log(this.data.firstlng)
    console.log(this.data.finallylat)
    console.log(this.data.finallylng)
    qqmapsdk.direction({
      mode: 'transit', //'transit'(公交路线规划)
      //from参数不填默认当前地址
      from: {
        latitude: this.data.firstlat,
        longitude: this.data.firstlng
      }, //{}<=这个形式
      to: {
        latitude: this.data.finallylat,
        longitude: this.data.finallylng
      },
      success: function(res) {
        console.log(res);
        var ret = res.result.routes;
        _this.setData({
          ret: ret
        })
      },
    })
  },

  toDetails(e) {
    var number = e.currentTarget.dataset.index;
    console.log(this.data.finallyStation)
    console.log(number);
    wx.navigateTo({
      url: 'underground_detail/underground_details?firstlat=' + this.data.firstlat +
        '&firstlng=' + this.data.firstlng +
        '&finallylat=' + this.data.finallylat +
        '&finallylng=' + this.data.finallylng +
        '&finallyStation' + this.data.finallyStation+
        '&number=' + number +
        '&firstStation=' + this.data.firstStation ,
    })


  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})